<%@ page contentType="text/html;charset=UTF-8"%>
<%@ page import="java.sql.*"%>
<%@ page import="java.util.*"%>
<%@ page import="com.gzgi.framework.*"%>
<%@ page import="com.gzgi.framework.util.*"%>
<%@ page import="com.gzgi.framework.context.*"%>
<%@ include file="/pages/system/checkAdmin.jsp"%>
<%
 
    String sql = request.getParameter("sql");
	if(sql != null){
		SQLFormatter f = new SQLFormatter();
		sql = f.format(sql);
		Connection con = null;
        PreparedStatement psmt = null;
		ResultSet rs = null;
		List rows = new ArrayList();
		try {
			    con = ContextFactory.getConnection();
				if(sql.indexOf(";")>0){
					StringTokenizer token = new StringTokenizer(sql, ";");
					while(token.hasMoreTokens()){
						String tmp = token.nextToken();
						System.out.println(tmp);
						if(tmp.trim().length() == 0){
							continue;
						}
						psmt = con.prepareStatement(tmp);
				        psmt.executeUpdate();
				        psmt.close();
					    psmt = null;
					}
				}else{
					System.out.println(sql);
				    psmt = con.prepareStatement(sql);
				    psmt.executeUpdate();
				    psmt.close();
					psmt = null;
				}
			
			out.println("<br><div align=center>Commond OK</div><br>");

		} catch (Exception ex) {
			ex.printStackTrace();
			throw new RuntimeException(ex.getMessage());
		} finally{
			try {
				if (con != null && !con.isClosed()) {
					con.close();
				}
			} catch (Exception ex) {
				ex.printStackTrace();
			}
		}
	}
%>
<center>
<form method="post" action=""><textarea name="sql" rows="20"
	cols="86">
<%=sql != null ? sql : ""%>
</textarea> <br>
<br>
<input type="submit" name="submit" value="submit"></form>
</center>